home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1160 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.4 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Better template syntax?
  5. Date: 18 Apr 1996 21:35:05 GMT
  6. Organization: Technical University of Berlin
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <3176A9E8.555D@cs.tu-berlin.de>
  9. References: <31741E6C.53CA@cs.tu-berlin.de> <317673A9.2EBB@datalytics.com>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset="us-ascii"
  13. Content-Transfer-Encoding: 7bit
  14. X-Nntp-Posting-Host: 130.149.17.233
  15. X-Mailer: Mozilla 2.0 (Win95; I)
  16. X-Lines: 67
  17. Content-Length: 2390
  18. Originator: clamage@taumet
  19.  
  20. Rob Stewart wrote:
  21. > Roman Lechtchinsky wrote:
  22. > >
  23. > > Hi,
  24. > >
  25. > > sorry for being curious but I'm only human... My question is: when declaring
  26. > > templates, why isn't it required to declare what one expects of the
  27. > > template's parameters? Let's create a template function:
  28. > >
  29. > > template<class T> bool equal( const T& t1, const T& t2 )
  30. > > {
  31. > >   return t1==t2;
  32. > > }
  33. > >
  34. > > Now, personally I would prefer to write something like:
  35. > >
  36. > > template<class T { bool operator==( const T& t ) const; }> ...
  37. > >[...]
  38. > I can't answer whether this has been considered (or rejected),
  39.  
  40. Yes, it has been. I forgot that D&E contains a ( rather short ) discussion on 
  41. this topic. Probably I should have written: "Has there been an attempt to 
  42. define this", a question still unanswered.
  43.  
  44. > but I can see a problem with your proposal.  What if a template
  45. > required ten, fifteen, twenty mfs in its parameterizing type?
  46. > What if those mfs have many parameters?  The resulting list of
  47. > mfs and parameters would become quite ungainly.
  48.  
  49. Actually, when I define a template I usually describe what it expects from 
  50. its parameters in a comment. This means I have to write this list anyway. Do 
  51. other programmers do it?
  52.  
  53.  
  54. > Perhaps you could declare a class with the exact interface you
  55. > expect and provide that as a model for the parameterizing type?
  56. > This still leaves issues like equivalence.  Are implicit
  57. > conversion allowed in mfs of a parameterizing type in order to
  58. > match the model?  At what point do you decide there is no match?
  59.  
  60. I'm currently trying to define how this can be handled. In general, I think 
  61. the following would do: a function matches a function required by the 
  62. template if
  63. a) its return type can be implicitly converted to the required return type 
  64. and
  65. b) the types of its parameters can be implicitly converted to the types of 
  66. the correspondenting required parameters.
  67. I wonder if someone has already tried this and what the results are.
  68.  
  69. > What about the template code?  What if it you misuse the
  70. > parameterizing type relative to your model?  Is the model wrong
  71. > or is your code wrong?
  72.  
  73. I'm not sure what you mean here.
  74.  
  75. > There's probably a lot more I haven't thought of yet. 
  76. Yes, definitely. However, there's probably a lot more that hasn't been 
  77. thought of ( or that is being thought of a this very moment ;-) about 
  78. templates as well.
  79.  
  80. Bye
  81.  
  82. Roman
  83.  
  84.  
  85. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  86. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  87. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  88. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  89. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  90.